home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / bench / x.txt / 000032_fdc@watsun.cc.columbia.edu_Fri Oct 5 10:37:37 EDT 2001.msg < prev    next >
Text File  |  2020-01-01  |  5KB  |  151 lines

  1. Article: 12840 of comp.protocols.kermit.misc
  2. Path: newsmaster.cc.columbia.edu!watsun.cc.columbia.edu!fdc
  3. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  4. Newsgroups: comp.unix.aix,comp.protocols.kermit.misc
  5. Subject: Re: ftp download with help of a file
  6. Date: 5 Oct 2001 14:35:38 GMT
  7. Organization: Columbia University
  8. Lines: 134
  9. Message-ID: <9pkgfq$ipf$1@newsmaster.cc.columbia.edu>
  10. References: <5e23bad3.0110050335.3c8e127@posting.google.com>
  11. NNTP-Posting-Host: watsun.cc.columbia.edu
  12. X-Trace: newsmaster.cc.columbia.edu 1002292538 19247 128.59.39.2 (5 Oct 2001 14:35:38 GMT)
  13. X-Complaints-To: postmaster@columbia.edu
  14. NNTP-Posting-Date: 5 Oct 2001 14:35:38 GMT
  15. Xref: newsmaster.cc.columbia.edu comp.unix.aix:223793 comp.protocols.kermit.misc:12840
  16.  
  17. In article <5e23bad3.0110050335.3c8e127@posting.google.com>,
  18. antonio <antonio.napoleone@bedag.ch> wrote:
  19.  
  20. : We download datfiles for virusengines via ftp. Usually we are doing this
  21. : automatically, but since a while we are having problems by getting several
  22. : files in the same remotedirectory with the mget-command.  In some
  23. : directorys, downloading of those files works fine but in other not.  Now i
  24. : try to download file by file, but i'm not very experienced in doing this.
  25. : What i do is getting the FILELIST from the remoteserver and figure out the
  26. : filenames with help of the grep and awk commands. Now my list looks like
  27. : this:
  28. : AVH32DLL.DL_
  29. : VIRSIG.DA_
  30. : VIRINFO.DA_
  31. : README.TX_
  32. : Is it possible to connect to the ftp-host, get each filename from the
  33. : list, download it and close the connection, after i dowloaded every
  34. : file, or do i have to connect, get 1 file, close, and so on.
  35. This would require a bit more flexibility than you'll find in the regular
  36. FTP client.  C-Kermit 8.0:
  37.  
  38.   http://www.columbia.edu/kermit/ck80.html
  39.  
  40. includes a new scriptable FTP client that will let you do this:
  41.  
  42.   http://www.columbia.edu/kermit/ftpclient.html
  43.  
  44. A scripting tutorial is here:
  45.  
  46.   http://www.columbia.edu/kermit/ckscripts.html
  47.  
  48. And an FTP-specific scripting tutorial is here:
  49.  
  50.   http://www.columbia.edu/kermit/ftpscripts.html
  51.  
  52. And complete documentation is here:
  53.  
  54.   http://www.columbia.edu/kermit/ckermit3.html#x3
  55.  
  56. Here is a script that gets the list of filenames:
  57.  
  58.   cd somelocaldirectory
  59.   ftp open foo.bar.com /user:myname /password:secret
  60.   if fail exit 1 Can't reach host
  61.   if not \v(ftp_loggedin) exit 1 FTP login failed
  62.   ftp cd blah/blah/somepath
  63.   if fail exit 1 Directory change failed
  64.   ftp get /namelist:mylist
  65.   if fail exit 1 Can't get list of filenames
  66.   ftp bye  
  67.  
  68. Obviously we don't recommend putting passwords in scripts; better methods
  69. are available.  The method shown above was chosen for brevity.  If you
  70. are using anonymous ftp, the command would be:
  71.  
  72.   ftp open foo.bar.com /anonymous
  73.  
  74. Now you have the list of filenames in the local file called 'mylist'.
  75. At this point, you should consider what you want to do with it.  One
  76. strategy, as you suggest, is to open a new FTP session for each file.
  77. This can be done as follows (still in Kermit):
  78.  
  79.   fopen /read \%c myfile
  80.   if fail exit 1 Can't open file list
  81.   while not \f_eof(\%c) {
  82.       fread /line \%c filename
  83.       if fail break
  84.       ftp open foo.bar.com /user:myname /password:secret
  85.       if fail exit 1 Can't reach host
  86.       if not \v(ftp_loggedin) exit 1 FTP login failed
  87.       ftp cd blah/blah/somepath
  88.       ftp get \m(filename)
  89.       if fail exit 1 \m(filename): Download failed
  90.       ftp bye
  91.   }
  92.  
  93. This is a sort of brute-force attack, and I'm not sure it does what you
  94. want anyway.  What happens if a download fails on a particular file?
  95.  
  96. Here is a more elegant solution:
  97.  
  98.   cd somelocaldirectory
  99.   delete *
  100.   ftp open foo.bar.com /user:myname /password:secret
  101.   if fail exit 1 Can't reach host
  102.   if not \v(ftp_loggedin) exit 1 FTP login failed
  103.   ftp cd blah/blah/somepath
  104.   if fail exit 1 Directory change failed
  105.   while true {
  106.       ftp get /update *      
  107.       if success break
  108.   }
  109.   ftp bye  
  110.  
  111. Here we clean out any old copies of the files, make the FTP connection to
  112. the server, cd to the desired server directory, and ask it to send us all
  113. the files in update mode.  This means: if I already have a current copy of
  114. a file, don't bother to send it, but if I don't, then please do send it.
  115.  
  116. If this succeeds, we're done.  If it fails, we try again, automatically
  117. skipping the files that were sent previously, and so on until all the files
  118. have been sent.
  119.  
  120. We can make this script both more robust and more efficient:
  121.  
  122.   cd somelocaldirectory
  123.   delete *
  124.  
  125.   while true {
  126.       ftp open foo.bar.com /user:myname /password:secret
  127.       if fail exit 1 Can't reach host
  128.       if not \v(ftp_loggedin) exit 1 FTP login failed
  129.       ftp cd blah/blah/somepath
  130.       if fail exit 1 Directory change failed
  131.       while true {
  132.       ftp get /recover /update *      
  133.       if success goto done
  134.       if not \v(ftp_connected) break
  135.       }
  136.       ftp bye  
  137.   }
  138.   done:
  139.   
  140. This allows for the case when the connection is lost.  When this happens,
  141. the script automatically goes back and reestablishes the connection and
  142. restarts the download; if the connection is not lost, however, it does not
  143. needlessly break the connection and reestablish it.  In case a long file was
  144. interrupted in the middle, the /RECOVER option makes the download resume
  145. from the point of failure.
  146.  
  147. - Frank
  148.